package com.myidis.mapper;

import com.myidis.entity.*;
import com.myidis.request.SearchReq;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

public interface SignalQuotaManagementMapper {

    @Select("Select * from signal_analysis_quota_bycombination where combination = #{sea};")
    @Results({
            @Result(property = "quota", column = "quota"),
            @Result(property = "dataitem", column = "dataitem")
    })
    ArrayList<SignalQuota> getByCombination(String sea);

    @Select("Select * from signal_analysis_quota_bysubject where subject = #{sea};")
    @Results({
            @Result(property = "quota", column = "quota"),
            @Result(property = "dataitem", column = "dataitem")
    })
    ArrayList<SignalQuota> getBySubject(String sea);

    @Select("Select * from signal_threshold where subject = #{keyWord1} and quota = #{keyWord2} ;")
    @Results({
            @Result(property = "redValue", column = "redValue"),
            @Result(property = "greenValue", column = "greenValue"),
            @Result(property = "yellowValue", column = "yellowValue"),
            @Result(property = "blueValue", column = "blueValue"),
    })
    SignalThreshold getThreshold(SearchReq sea);

    @Select("SELECT * FROM signal_quota_combination;")
    @Results({
            @Result(property = "name", column = "combination"),
            @Result(property = "creator", column = "creator"),
            @Result(property = "creatTime", column = "creTime"),
            @Result(property = "lastChange", column = "lastTime"),
            @Result(property = "benchmarkValue", column = "benchmark")
    })
    ArrayList<IndexCombination> combinationlist();

    @Insert("INSERT intO signal_quota_combination( combination, creator,benchmark, creTime, lastTime) " +
            "VALUES( #{name}, #{creator}, #{benchmarkValue},  #{creatTime}, #{lastChange})")
    int addCombination(IndexCombination a);

    @Insert("INSERT intO signal_analysis_quota_bycombination (time, combination, quota, benchmark, dataitem) " +
            "VALUES( #{combination}, #{quota}, #{benchmark},  #{dataitem})")
    int addToCombination(SignalQuota a);

    @Insert("INSERT intO signal_analysis_quota_bysubject(subject, quota, benchmark, dataitem) " +
            "VALUES( #{subject}, #{quota}, #{benchmark},  #{dataitem})")
    int addToSubject(SignalQuota a);

    @Insert("INSERT intO signal_threshold(subject, quota, blueValue, redValue, yellowValue, greenValue) VALUES( #{subject}, #{quota}, #{blueValue}, " +
            "#{redValue}, {yellowValue}, {greenValue})")
    int addThreshold(SignalThreshold result);

    @Delete("DELETE FROM signal_analysis_quota_bysubject WHERE id = #{id};")
    int delectInSubject(int id);

    @Delete("DELETE FROM signal_analysis_quota_bycombination WHERE id = #{id};")
    int delectInCombination(int id);

    @Delete("DELETE FROM signal_quota_combination WHERE id = #{id};")
    int delectCombination(int id);



}
